package concurrent;

import util.DateUtil;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * Created by yzy on 2019-05-23 14:42
 */
public class Athlete implements Runnable {

    private CyclicBarrier cyclicBarrier;
    private String name;
    private long waitTime;

    public Athlete(CyclicBarrier cyclicBarrier, String name, long waitTime) {
        this.cyclicBarrier = cyclicBarrier;
        this.name = name;
        this.waitTime = waitTime;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(waitTime);
            cyclicBarrier.await();
            System.out.println(name + "wait "+waitTime+" is ready...");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }
    }
}
